import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2022-09-13
 * Time: 20:26
 */
public class SendEmail {

    public static void sendEmail(String FromEmail, String ToEmail, String subject, String message,String password){
        SimpleEmail email = new SimpleEmail();
        //qq邮件服务器端口号
        email.setSslSmtpPort("465");
        email.setHostName("smtp.qq.com");
        email.setAuthentication(FromEmail,password);
        email.setCharset("UTF-8");
        //拓展功能：1.群发 2.发文件
        try{
            email.addTo(ToEmail);
            email.setFrom(FromEmail);
            email.setSubject(subject);
            email.setMsg(message);
            email.send();
        } catch (EmailException e){
            e.printStackTrace();
        }
    }
}
